package com.chnagli06.method_more;

public class MyArrays {
    public void sort (int [] a,String way){
        if("asc".equals(way)){
            for(int i=0;i<a.length-1;i++){
                for(int j=0;j<a.length-1-i;j++){
                    if(a[j]>a[j+1]){
                        swap(a,j,j+1);
                    }
                }
            }
        }
        else if("desc".equals(way)){
            for(int i=0;i<a.length-1;i++){
                for(int j=0;j<a.length-1-i;j++){
                    if(a[j]<a[j+1]){
                        swap(a,j,j+1);
                    }
                }
            }
        }
        else {
            System.out.println("您输入的排序方式有误");
        }
    }
    public void swap(int [] a,int i,int j){
        int temp=a[i];
        a[i] = a[j];
        a[j] = temp;
    }
}
